package com.peenongsaban.freelance.service;

import java.util.Vector;

import com.peenongsaban.freelance.bean.AptitudeTypeBean;
import com.peenongsaban.freelance.bean.PostJobBean;
import com.peenongsaban.freelance.bean.RequestJobBean;
import com.peenongsaban.freelance.dao.JobDetailDAO;
import com.peenongsaban.freelance.dao.impl.JobDetailDAOImpl;
import com.peenongsaban.freelance.model.AuthorizeJobBean;
import com.peenongsaban.freelance.model.JobDetailModel;
import com.peenongsaban.freelance.utils.ConstantUtils;

/*
 * List job detail
 * List job category
 * List last job
 * Check authorize job
 */
public class JobDetailService {
	public PostJobBean getListJobDetail(JobDetailModel model) {
		PostJobBean bean = new PostJobBean();
		JobDetailDAO dao = new JobDetailDAOImpl();
		bean = dao.selectJobDetail(model.getPostJobId());
		return bean;
	}

	public Vector<AptitudeTypeBean> getListJobCategoryJob() {
		Vector<AptitudeTypeBean> vec = new Vector<AptitudeTypeBean>();
		JobDetailDAO dao = new JobDetailDAOImpl();
		vec = dao.listCategoryJob();
		return vec;
	}

	public Vector<PostJobBean> getListLastJob() {
		Vector<PostJobBean> vec = new Vector<PostJobBean>();
		JobDetailDAO dao = new JobDetailDAOImpl();
		vec = dao.listLastPostJob();
		return vec;
	}
	
	public String getAptitudeTypeNameOfJobDetail(JobDetailModel model) {
		Vector<Integer> id = new Vector<Integer>();
		Vector<String> name = new Vector<String>();
		boolean chk = true;
		for (int i = 0; i < model.getJobDetail().getListAptitude().size(); i++) {
			AptitudeTypeBean temp = model.getJobDetail().getListAptitude()
					.get(i).getAptitudeType();
			if (id.size() != 0) {
				for (int j = 0; j < id.size(); j++) {
					if (temp.getAptitudeTypeID() == id.get(j)) {
						chk = false;
						break;
					} else {
						chk = true;
					}
				}
				if (chk) {
					id.add(temp.getAptitudeTypeID());
					name.add(temp.getAptitudeTypeName());
				}
			} else {
				id.add(temp.getAptitudeTypeID());
				name.add(temp.getAptitudeTypeName());
			}
		}
		String result = name.toString().substring(1,
				name.toString().length() - 1);
		return result;
	}
	
	public AuthorizeJobBean chackAuthorizeJob(String idCard,String postId){
		AuthorizeJobBean bean = new AuthorizeJobBean();
		JobDetailDAO dao = new JobDetailDAOImpl();
		bean = dao.getAuthorizeJob(idCard, postId);
		return bean;
	}
	
	
	public Vector<RequestJobBean> getUserRequestJob(String postID,int statusId){
		Vector<RequestJobBean> bean = new Vector<RequestJobBean>();
		JobDetailDAO dao = new JobDetailDAOImpl();
		bean = dao.getUserRequestJobDetail(postID, statusId);
		return bean;
	}
	
	public RequestJobBean getRequestJobDeatil(String idCard,String postID){
		RequestJobBean bean = new RequestJobBean();
		JobDetailDAO dao = new JobDetailDAOImpl();
		bean = dao.requestJobDetail(idCard,postID);
		return bean;
	}

}
